<template>
	<view class="page-main">
		<navbar title="评价"></navbar>
		<view class="rider-wrapper">
			<view class="title">您对配送员满意吗？</view>
			<view class="user-box fa">
				<image class="avatar" :src="avatar" mode=""></image>
				<view class="name">{{name}}</view>
			</view>
			<view class="rate-box bgf">
				<view class="rate-list fa">
					<view class="name">送货速度</view>
					<uni-rate v-model="speed"/>
				</view>
				<view class="rate-list fa">
					<view class="name">服务态度</view>
					<uni-rate v-model="manner"/>
				</view>
				<view class="rate-list fa">
					<view class="name">配送服务</view>
					<uni-rate v-model="distribution"/>
				</view>
			</view>
		</view>
		<view class="remarks-box bgf">
			<view>配送员评价</view>
			<view class="remarks-wrapper">
				<textarea class="feel" placeholder-class="placeclass" placeholder="说说您对这次交易的感受吧~" v-model="content"></textarea>
				<view class="upload-wrapper">
					<view class="upload-box flex fww">
						<view class="upload-list" v-for="(item, index) in imageList" :key="index" @click="uploadImage(index)">
							<image :src="item"></image>
						</view>
						<view class="upload-list" @click="uploadImage(-1)" v-if="imageList.length < 9">
							<image src="../../static/upload.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view>
			<view class="operate-box fa">
				<view class="addbtn fa jcc fwb" @click="evaluateNow">立即评价</view>
			</view>
			<view class="operate-place"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				ordersId: '',
				avatar: '',
				name: '',
				manner: 5, //商品评价星星
				distribution: 5, //描述相符评价星星
				speed: 5,
				content: '', //商品评价
				imageList: [],
				lock: true
			};
		},
		onLoad(options) {
			if(options.id) {
				this.id = options.id
				this.ordersId = options.ordersId
				this.getCourier()
			}
		},
		methods: {
			getCourier() {
				this.api.oneCourierFunc({
					courierId: this.id
				}).then(res => {
					if(res.code == 200) {
						this.avatar = res.data.avatar
						this.name = res.data.name
					}
				})
			},
			uploadImage(index) {
				uni.chooseImage({
					count: 1,
					mediaType: ['image'],
					sourceType: ['album', 'camera'],
					success: result => {
						this.api.uploadFileFunc(result.tempFiles[0].path).then(res => {
							if(index < 0) {
								this.imageList.push(res.url)
							}else {
								this.imageList.splice(index, 1, res.url)
							}
						})
					}
				})
			},
			// 立即评价
			evaluateNow() {
				if(!this.content) return uni.showToast({
					title: '请输入评价内容',
					icon: 'none'
				})
				if(!this.lock) return false
				this.lock = false
				this.api.orderCommentFunc({
					ordersId: this.ordersId,
					courierId: this.id,
					manner: this.manner,
					distribution: this.distribution,
					speed: this.speed,
					content: this.content,
					image: this.imageList.join()
				}).then(res => {
					if(res.code == 200) {
						uni.showToast({
							title: '评价成功'
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					}else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.lock = true
					}
				}).catch(err => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					this.lock = true
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-main{
		padding-bottom: 30rpx;
	}
	.rider-wrapper{
		margin: 20rpx 24rpx 0;
		padding-top: 34rpx;
		border-radius: 10rpx;
		background-color: #fff;
		.title{
			margin: 0 24rpx;
			font-size: 32rpx;
			font-weight: bold;
		}
		.user-box{
			margin-top: 46rpx;
			padding: 0 26rpx;
		}
		.avatar{
			margin-right: 14rpx;
			width: 98rpx;
			height: 98rpx;
			border-radius: 10rpx;
		}
		.name{
			font-size: 32rpx;
		}
	}
	.rate-box{
		.rate-list{
			padding: 0 24rpx;
			height: 84rpx;
			border-bottom: 2rpx solid #E6E6E6;
			&:last-child{
				border-bottom: none;
			}
			.name{
				margin-right: 24rpx;
				font-size: 26rpx;
				color: #777;
			}
		}
	}
	.remarks-box{
		margin: 16rpx 24rpx 0;
		padding: 24rpx 20rpx;
		border-radius: 10rpx;
		.remarks-wrapper{
			margin-top: 24rpx;
			padding: 24rpx;
			border-radius: 10rpx;
			background: #f8f8f8;
			box-sizing: border-box;
		}
		.feel{
			width: 100%;
			height: 150rpx;
			font-size: 24rpx;
			box-sizing: border-box;
		}
		.placeclass{
			font-size: 24rpx;
		}
		.upload-wrapper{
			border-radius: 10rpx;
			.upload-box{
				margin-top: 26rpx;
			}
			.upload-list{
				margin-right: 16rpx;
				margin-bottom: 16rpx;
				width: 152rpx;
				height: 152rpx;
				&:nth-child(3n) {
					margin-right: 0;
				}
				image{
					width: 152rpx;
					height: 152rpx;
				}
			}
		}
	}
	.operate-place{
		height: calc(env(safe-area-inset-bottom) + 110rpx);
	}
	.operate-box{
		position: fixed;
		bottom: 0;
		bottom: env(safe-area-inset-bottom);
		left: 0;
		right: 0;
		padding: 0 70rpx;
		height: 184rpx;
		z-index: 999;
		.addbtn{
			width: 100%;
			height: 88rpx;
			border-radius: 44rpx;
			color: #fff;
			background: var(--theme);
		}
	}
</style>
